package lancooControl;

import android.content.Context;
import android.os.Handler;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.lancooznbk.R;

import org.apache.commons.lang3.StringEscapeUtils;

/**
 * Created by Administrator on 2017/8/17/017.
 */

public class CustomAnswerChoiceView extends RelativeLayout {

    // 返回按钮控件
    public Button BtnChoice;
    // 标题Tv
    private TextView TvChoice;

    public CustomAnswerChoiceView(Context context) {
        super(context);

        // 加载布局
        LayoutInflater.from(context).inflate(R.layout.custom_answer_choice, this);

        // 获取控件
        BtnChoice = (Button) findViewById(R.id.btn_choice);
        TvChoice = (TextView) findViewById(R.id.tv_choice);

    }


    /*
    * 设置选项属性
    * @ strIndex  选项编号
    * @ colorId1  选项编号颜色
    * @ resId  选项编号底图
    * @ Option 选项文本
    * @ colorId2 选项文本颜色
    * */
    Handler htmlHandlerOption = new Handler();
    public void setAnswerChoice(String strIndex, int colorId1, int resId, final String Option, int colorId2){
        BtnChoice.setText(strIndex);
        BtnChoice.setTextColor(colorId1);
        BtnChoice.setBackgroundResource(resId);

        new Thread(new Runnable()
        {
            @Override
            public void run()
            {

                String OptionA = StringEscapeUtils.unescapeXml(Option);

                final Spanned text = Html.fromHtml(OptionA, Control.imgGetter,null);
                htmlHandlerOption.post(new Runnable()
                {
                    @Override
                    public void run()
                    {
                        TvChoice.setText(text);
                    }
                });
            }
        }).start();

        TvChoice.setTextColor(colorId2);

    }

}